/************************************************
 * Copyright (c) 2007 ~ 2009, 
 * All rights reserved.
 * Version   : 1.0
 * Author    : lengsh@gmail.com 
 * Date      : 2008.1.2
 ***********************************************/

#ifndef _PANDA_HELPER_H______
#define _PANDA_HELPER_H______

#include <string>
#include <map>
#include <iostream>
#include <glib.h>
#include <pthread.h>
#include <string.h>
#include "ICache.h"
#include "IStorage.h"
#include "define.h"

using namespace panda;
using namespace std;
class Helper 
{
	protected:
		static Helper *_instance;
		bool  Startup(const char *filename);
		ICache *m_pCache;
		IStorage *m_pStorage;
	protected:
		string m_sConfFile;
		string m_sCache_Cfg;
		string m_sStorage_Cfg;
                string m_sIPAcl; //m_sBackup_Log_Dir;
                int     m_iPort;
                int     m_iwPort;
                int     m_iThreads;
	public:
		int getPort(){ return m_iPort; }
		int getWPort(){ return m_iwPort; }
		int getThreads(){ return m_iThreads; }
		const char *getIPAcl() { return m_sIPAcl.c_str(); }

		static Helper *Instance(const char *conf = NULL);
		static void Release( bool bForce = false);
	protected:
		Helper();
		virtual ~Helper();
		int get_mem_return_info(char **wbuf, int retcode,unsigned &wsize, unsigned &wbytes);

		int write(const char *data, unsigned dlen);
		int read(const char *data, unsigned dlen, char **wbuf,unsigned &wsize, unsigned &wbytes);
		int incr(const char *data, unsigned dlen, char **wbuf,unsigned &wsize, unsigned &wbytes);
		int decr(const char *data, unsigned dlen, char **rval,unsigned &wsize, unsigned &wbytes);
		int remove(const char *data, unsigned dlen);
	public:
                bool InitCache(const char *config);
                int ResetCache(const char *ip, int port);
                int Do_Method(int method, char *data, unsigned dlen, char **wbuf, unsigned &wsize, unsigned &wbytes);

};


#endif 

